import type { DragElement, DragTableElementColumn, PaperAlign, PaperSize } from "@/typings";
import { compoundProvider } from "@/utils";

/**
 * @description 打印模板跳转类别
 */
export enum PRINT_TAG {
  /**
   * @description 复制
   */
  COPY = "copy",
  /**
   * @description 新增
   */
  ADD = "add",
  /**
   * @description 查看
   */
  VIEW = "view"
}

/**
 * @description 属性白名单，名单中的属性可以选择自定义属性
 */
// const propertyWhiteList: string[] = ["text", "longText", "barcode", "qrcode"];

/**
 * @description 纸张大小
 */
export const PAPER_SIZE: PaperSize[] = [
  {
    type: "A3",
    label: "A3",
    width: 297,
    height: 420,
    unit: "mm",
    default: false
  },
  {
    type: "A4",
    label: "A4",
    width: 210,
    height: 297,
    unit: "mm",
    default: true
  },
  {
    type: "A5",
    label: "A5",
    width: 148,
    height: 210,
    unit: "mm",
    default: false
  },
  {
    type: "B3",
    label: "B3",
    width: 353,
    height: 500,
    unit: "mm",
    default: false
  },
  {
    type: "B4",
    label: "B4",
    width: 250,
    height: 352,
    unit: "mm",
    default: false
  },
  {
    type: "B5",
    label: "B5",
    width: 176,
    height: 250,
    unit: "mm",
    default: false
  }
];

/**
 * @description 对齐方式
 */
export const PAPER_ALIGN: PaperAlign[] = [
  {
    tag: "glyphicon-object-align-left",
    label: "左对齐",
    type: "left",
    icon: "zuoduiqi"
  },
  {
    tag: "glyphicon-object-align-vertical",
    label: "居中",
    type: "vertical",
    icon: "zuoyoujuzhong"
  },
  {
    tag: "glyphicon-object-align-right",
    label: "右对齐",
    type: "right",
    icon: "youduiqi"
  },
  {
    tag: "glyphicon-object-align-top",
    label: "顶部对齐",
    type: "top",
    icon: "dingbuduiqi"
  },
  {
    tag: "glyphicon-object-align-horizontal",
    label: "垂直居中",
    type: "horizontal",
    icon: "shangxiajuzhong"
  },
  {
    tag: "glyphicon-object-align-bottom",
    label: "底部对齐",
    type: "bottom",
    icon: "dibuduiqi"
  },
  {
    tag: "glyphicon-resize-horizontal",
    label: "横向分散",
    type: "distributeHor",
    icon: "zuoyoufensan"
  },
  {
    tag: "glyphicon-resize-vertical",
    label: "纵向分散",
    type: "distributeVer",
    icon: "shangxiafensan"
  }
];

/**
 * @description 拖拽属性
 */
export const DRAG_LIST: DragElement[] = [
  {
    tag: "defaultModule.text",
    tid: "defaultModule.text",
    type: "text",
    isShow: true,
    title: "短文本",
    icon: "danhangwenben",
    discription: "短文本占位小",
    options: {
      width: 140,
      height: 16,
      fontSize: 14,
      fields: []
    }
  },
  {
    tag: "defaultModule.longText",
    tid: "defaultModule.longText",
    type: "longText",
    isShow: true,
    title: "长文本",
    icon: "duohangwenben",
    discription: "长文本占位大",
    options: {
      width: 300,
      height: 32,
      fontSize: 14,
      fields: []
    }
  },
  {
    tag: "defaultModule.customText",
    tid: "defaultModule.customText",
    type: "text",
    isShow: true,
    title: "自定义文本",
    icon: "zidingyiwenben",
    discription: "自定义文本为固定值，无引用",
    options: {
      width: 140,
      height: 16,
      fontSize: 14
    }
  },
  {
    tag: "defaultModule.emptyTable",
    tid: "defaultModule.emptyTable",
    type: "table",
    isShow: true,
    title: "表格",
    icon: "biaoge",
    discription: "表格占位，可引用数据",
    options: {
      width: 500,
      height: 60
    },
    columns: [
      [
        { columnId: "", field: "", title: "" },
        { columnId: "", field: "", title: "" }
      ]
    ]
  },
  {
    tag: "defaultModule.image",
    tid: "defaultModule.image",
    type: "image",
    isShow: true,
    title: "图片",
    icon: "tupian1",
    discription: "图片占位，可用于引用图片或者logo",
    options: {
      width: 70,
      height: 70
    }
  },
  {
    tag: "defaultModule.barcode",
    tid: "defaultModule.barcode",
    type: "barcode",
    isShow: true,
    title: "条形码",
    icon: "tiaoxingma",
    discription: "条形码占位，可用于模板打印中的商品识别",
    options: {
      fields: []
    }
  },
  {
    tag: "defaultModule.qrcode",
    tid: "defaultModule.qrcode",
    type: "qrcode",
    isShow: true,
    title: "二维码",
    icon: "erweima",
    discription: "二维码占位，可用于模板打印中的商品识别",
    options: {
      width: 70,
      height: 70,
      fields: []
    }
  },
  {
    tag: "defaultModule.hline",
    tid: "defaultModule.hline",
    type: "hline",
    isShow: true,
    title: "横线",
    icon: "hengxian",
    discription: "横线",
    options: {}
  },
  {
    tag: "defaultModule.vline",
    tid: "defaultModule.vline",
    type: "vline",
    isShow: true,
    title: "竖线",
    icon: "shuxian",
    discription: "竖线",
    options: {}
  }
];

/**
 * @description 默认模板配置
 */
export const DEFAULT_TEMPLATE_CONFIG = {
  panels: [
    {
      index: 0,
      height: 297,
      width: 210,
      paperHeader: 27,
      paperFooter: 807,
      paperNumberDisabled: true,
      watermarkOptions: {
        content: "",
        rotate: 45,
        timestamp: false,
        format: "YYYY-MM-DD HH:mm"
      },
      printElements: [],
      paperNumberLeft: 0,
      paperNumberTop: 819
    }
  ]
};

/**
 * @description 模板字体格式选择列表
 */
export const FONT_FAMILY_LIST: Array<{ title: string; value: string }> = [
  { title: "微软雅黑", value: "Microsoft YaHei" },
  { title: "黑体", value: "STHeitiSC-Light" },
  { title: "思源黑体", value: "SourceHanSansCN-Normal" },
  { title: "王羲之书法体", value: "王羲之书法体" },
  { title: "宋体", value: "SimSun" },
  { title: "华为楷体", value: "STKaiti" },
  { title: "cursive", value: "cursive" }
];

/**
 * @description 自定义Provider
 * @param hiprint
 * @param columns
 * @returns
 */
export function customProvider(hiprint: any, columns: DragTableElementColumn[] = []) {
  // todo 这里需要处理单据的信息进行转换，然后转换成数组放入拖拽属性的fields中进行选择，由于单据未处理所以先搁置
  const newDragList = compoundProvider(columns, DRAG_LIST);
  const addElementTypes = function (context: any) {
    context.removePrintElementTypes("defaultModule");
    context.addPrintElementTypes("defaultModule", [new hiprint.PrintElementTypeGroup("常规", newDragList)]);
  };
  return {
    addElementTypes: addElementTypes
  };
}
